package com.project.util;

import java.io.IOException;
import java.io.StringWriter;

import com.fasterxml.jackson.databind.ObjectMapper;


/**
 * Jackson帮助类
 * 
 * @author weimingsen
 * 
 */
public class JacksonUtil {
	private static ObjectMapper mapper = null;

	public static String objToJson(Object obj) throws IOException {
		if(mapper == null){
			mapper = new ObjectMapper();
//			mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);//（禁止SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS）			
		}
		StringWriter writer = new StringWriter();
		mapper.writeValue(writer, obj);
		String json = writer.toString();
		writer.close();
		return json;
	}

}